package com.thghh;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.PathUtil;
import cn.hutool.core.util.CharsetUtil;
import com.thghh.service.GenerateSqlService;
import com.thghh.util.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) throws IOException {
        String[] filePaths = args;
        GenerateSqlService generateSqlService = new GenerateSqlService();
        for (String filePath : filePaths) {
            List<String> sqlList = generateSqlService.generateSql(filePath);

            String fileName = FileUtils.mainName(filePath);
            String parentFile = FileUtil.getParent(filePath, 1);
            File sqlFile = FileUtil.touch(parentFile, fileName + ".sql");
            FileUtil.del(sqlFile);
            FileUtil.writeLines(sqlList, sqlFile, CharsetUtil.UTF_8);
        }


    }
}
